#!/usr/bin/env php
<?php

$loader = require_once __DIR__ . '/../vendor/autoload.php';
$loader->addPsr4('Proto2Test\\', __DIR__ . '\src');
$loader->loadClass('Proto2Test\\gm_notice_pay');

$addressBook = new gm_notice_pay();
$addressBook->setOrderId("333");
echo $addressBook;
$stream = $addressBook->toStream();


$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if($socket == false) {
    echo json_encode("socket 创建失败");
    exit;
}

//gametool 直接发到了gateway上
$ret = socket_connect($socket, '127.0.0.1', '5600');
if($ret == false) {
    echo json_encode("socket 连接失败");
    socket_close($socket);
    exit;
}

$userID = 1;
$svr_id = 1;

$kickOff = new gm_notice_pay();
$kickOff->setUserId($userID);

$packed = $kickOff->toStream();
echo $packed->getSize();

$len = 18 + $packed->getSize();
$cmd = 1999;
$uid = 0;
$seq = $svr_id;
$ret = 0;
$in = pack('N', $len);
$in .= pack('n', $cmd);
$in .= pack('N', $uid); 
$in .= pack('N', $seq); 
$in .= pack('N', $ret);
$in .= pack('a*', $packed);
if(!socket_write($socket, $in, strlen($in))) {
    echo json_encode("写入数据失败");
}

socket_close($socket);

// Write the new address book back to disk.
//file_put_contents($argv[1], $addressBook->toStream());